﻿<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asp="remove">

	<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>

	<xsl:template match="/">
		<xsl:choose>
			<xsl:when test="/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultstring">
				<xsl:value-of select="/SOAP-ENV:Envelope/SOAP-ENV:Body/SOAP-ENV:Fault/faultstring" />
			</xsl:when>
		  <xsl:when test="/SOAP-ENV:Envelope/SOAP-ENV:Body/Result/Item/Relationships/Item">
			<table cellpadding="3">
			  <tr>
				<th>
				  File Name
				</th>
				<th>
				  Modified On
				</th>
				<th>
				  Modified By
				</th>
			  </tr>
			  <xsl:apply-templates/>
			</table>
		  </xsl:when>
			<xsl:otherwise>
				Documents not found
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template match="Item">
		<xsl:apply-templates select="Relationships/Item"/>
	</xsl:template>

	<xsl:template match="Relationships/Item">
		<xsl:variable name="relUrl" select="related_id/@keyed_name" />
		<tr>
			<td>
				<a href="http://cpd2010{$relUrl}">
					<xsl:call-template name="substring-after-last">
						<xsl:with-param name="string" select="$relUrl" />
						<xsl:with-param name="delimiter" select="'/'" />
					</xsl:call-template>
				</a>
			</td>
			<td>
				<xsl:value-of select="modified_on" />
			</td>
			<td>
				<xsl:value-of select="modified_by_id/@keyed_name" />
			</td>
		</tr>
	</xsl:template>

	<xsl:template name="substring-after-last">
		<xsl:param name="string" />
		<xsl:param name="delimiter" />
		<xsl:choose>
			<xsl:when test="contains($string, $delimiter)">
				<xsl:call-template name="substring-after-last">
					<xsl:with-param name="string"
					  select="substring-after($string, $delimiter)" />
					<xsl:with-param name="delimiter" select="$delimiter" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$string" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>